// 通用响应类型
interface Result<T> {
  code: number;
  message: string;
  data: T;
}

// 用户相关类型
interface UserInfo {
  id: string;
  username: string;
  nickname: string;
  photo: string;
}

interface LoginParams {
  username: string;
  password: string;
}

interface RegisterParams {
  username: string;
  password: string;
  confirmedPassword: string;
}

// 账户相关类型
interface Account {
  id: string;
  userId: string;
  accountTypeId: string;
  name: string;
  balance: string;
  createdAt: string;
  updatedAt: string;
}

interface AccountType {
  id: string;
  name: string;
  description: string;
}

// 交易相关类型
interface Transaction {
  id: string;
  userId: string;
  accountId: string;
  categoryId: string;
  amount: string;
  type: 'INCOME' | 'EXPENSE';
  description: string;
  transactionDate: string;
  createdAt: string;
  updatedAt: string;
}

interface Category {
  id: string;
  name: string;
  type: 'INCOME' | 'EXPENSE';
  description: string;
}

interface TransactionCreateParams {
  accountId: string;
  categoryId: string;
  amount: string;
  type: 'INCOME' | 'EXPENSE';
  description?: string;
  transactionDate?: string;
}

interface TransactionUpdateParams {
  transactionId: string;
  categoryId?: string;
  amount?: string;
  description?: string;
}

// 统计相关类型
interface AccountStatistics {
  accountName: string;
  totalIncome: string;
  totalExpense: string;
  balance: string;
  startDate: string;
  endDate: string;
}

// 账户统计数据
interface AccountStatItem {
  INCOME: string;
  EXPENSE: string;
}

// 单个账户的统计信息
interface AccountStatInfo {
  accountName: string;
  income: string;
  expense: string;
}

// 所有账户的统计信息
interface AllAccountsStatistics {
  accountList: Array<AccountStatInfo>;  // 每个账户的统计列表
  totalIncome: string;
  totalExpense: string;
  netBalance: string;
  startDate: string;
  endDate: string;
}

// API 接口定义
const API = {
  // 用户相关接口
  USER: {
    LOGIN: '/api/user/login',
    REGISTER: '/api/user/register',
    GET_INFO: '/api/user/getInfo',
    UPDATE_INFO: '/api/user/updateUserInfo',
  },

  // 账户相关接口
  ACCOUNT: {
    CREATE: '/api/accounts/create',
    GET_BY_ID: '/api/accounts/getAccountById',
    GET_USER_ACCOUNTS: '/api/accounts/getUserAccounts',
    UPDATE_BALANCE: '/api/accounts/updateBalance',
    GET_SUMMARY: '/api/accounts/getAccountSummary',
  },

  // 交易相关接口
  TRANSACTION: {
    CREATE: '/api/transactions/create',
    DELETE: '/api/transactions/deleteTransaction',
    UPDATE: '/api/transactions/updateTransaction',
    GET_BY_ID: '/api/transactions/getTransactionById',
    GET_BY_ACCOUNT: '/api/transactions/getTransactionsByAccountId',
    GET_ACCOUNT_STATS: '/api/transactions/getAccountStatistics',
    GET_ALL_STATS: '/api/transactions/getAllAccountsStatistics',
    GET_USER_TRANSACTIONS: '/api/transactions/getUserTransactions',
  },

  // 文件上传接口
  FILE: {
    UPLOAD: '/api/file/upload',
    UPLOAD_BATCH: '/api/file/uploads',
  },
} as const;

// 错误码定义
const ResultCode = {
  SUCCESS: 200,

  // 客户端错误 4xx
  BAD_REQUEST: 400,
  UNAUTHORIZED: 401,
  FORBIDDEN: 403,
  NOT_FOUND: 404,

  // 用户相关错误 1000~1999
  USER_NOT_FOUND: 1000,
  USER_EXISTS: 1001,
  PASSWORD_ERROR: 1002,
  USERNAME_EMPTY: 1003,
  PASSWORD_EMPTY: 1004,
  PASSWORD_NOT_MATCH: 1005,
  USER_UPDATE_FAILED: 1006,

  // 账户相关错误 2000~2999
  ACCOUNT_NOT_FOUND: 2000,
  ACCOUNT_EXISTS: 2001,
  BALANCE_NOT_ENOUGH: 2002,

  // 交易相关错误 3000~3999
  TRANSACTION_NOT_FOUND: 3000,
  INVALID_AMOUNT: 3001,

  // 系统错误 5xx
  SYSTEM_ERROR: 500,
  SERVICE_UNAVAILABLE: 503,

  // 文件相关错误 4000~4999
  UPLOAD_FAILED: 4000,
  INVALID_FILE_TYPE: 4001,
  FILE_SIZE_EXCEEDED: 4002,
  PARTIAL_UPLOAD_FAILED: 4003,
} as const;

export type {
  Result,
  UserInfo,
  LoginParams,
  RegisterParams,
  Account,
  AccountType,
  Transaction,
  Category,
  TransactionCreateParams,
  TransactionUpdateParams,
  AccountStatistics,
  AllAccountsStatistics,
};

export { API, ResultCode }; 